﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Transport
{
    class BangGiaTheoMienControl
    {
         transportEntities db;

        public BangGiaTheoMienControl()
        {
            db = new transportEntities();
        }

        public List<BangGiaTheoMien> GiaTheoMien(string key)
        {
            var result = (from a in db.bang_gia_theo_lo_trinh
                         from b in db.chi_tiet_xe
                         from c in db.lo_trinh
                         from d in db.thuong_hieu
                         from e in db.miens
                         where a.ma_bien_so == b.bien_so && c.ma_lo_trinh == a.ma_lo_trinh && b.ma_thuong_hieu == d.ma_thuong_hieu && c.ma_mien == e.ma_mien && e.ten_mien == key
                         select new BangGiaTheoMien {
                                LoTrinh = c.ten_lo_trinh,
                                SoKm = c.so_km,
                                LoaiXe = d.so_cho,
                                HieuXe = d.ten_thuong_hieu,
                                GiaTien = a.gia_tien,
                                SoNgay = c.so_ngay,
                                ChiPhiVuotKm = a.chi_phi_vuot_km
                            }).ToList();

            return result;
        }

        public List<BangGiaTheoMien> GetGiaTheoMien(string key)
        {
            var result = (from a in db.bang_gia_theo_lo_trinh
                          from b in db.chi_tiet_xe
                          from c in db.lo_trinh
                          from d in db.thuong_hieu
                          from e in db.miens
                          where a.ma_bien_so == b.bien_so && c.ma_lo_trinh == a.ma_lo_trinh && b.ma_thuong_hieu == d.ma_thuong_hieu && c.ma_mien == e.ma_mien && e.ma_mien == key
                          select new BangGiaTheoMien
                          {
                              LoTrinh = c.ten_lo_trinh,
                              SoKm = c.so_km,
                              LoaiXe = d.so_cho,
                              HieuXe = d.ten_thuong_hieu,
                              GiaTien = a.gia_tien,
                              SoNgay = c.so_ngay,
                              ChiPhiVuotKm = a.chi_phi_vuot_km
                          }).ToList();

            return result;
        }

        public List<BangGiaTheoMien> GetGiaTheoMien()
        {
            var result = (from a in db.bang_gia_theo_lo_trinh
                          from b in db.chi_tiet_xe
                          from c in db.lo_trinh
                          from d in db.thuong_hieu
                          from e in db.miens
                          where a.ma_bien_so == b.bien_so && c.ma_lo_trinh == a.ma_lo_trinh && b.ma_thuong_hieu == d.ma_thuong_hieu && c.ma_mien == e.ma_mien
                          select new BangGiaTheoMien
                          {
                              LoTrinh = c.ten_lo_trinh,
                              SoKm = c.so_km,
                              LoaiXe = d.so_cho,
                              HieuXe = d.ten_thuong_hieu,
                              GiaTien = a.gia_tien,
                              SoNgay = c.so_ngay,
                              ChiPhiVuotKm = a.chi_phi_vuot_km
                          }).ToList();

            return result;
        }
    }   
}
